package com.zt.bigdata.flink.stream

import org.apache.flink.streaming.api.scala.function.WindowFunction
import org.apache.flink.streaming.api.windowing.windows.Window
import org.apache.flink.util.Collector

/**
  * @ClassName ProcessWindowFunction
  * @Description
  * @Author zhangtonghy
  * @Date 2019-07-17 09:20
  * @Copyright: 版权所有 (C) zt zt.
  * @注意 ：本内容仅限于zt内部传阅，禁止外泄以及用于其他的商业目的
  **/
abstract class ProcessWindowFunction[IN, OUT, KEY, W <: Window] extends WindowFunction[IN, OUT, KEY, W] {
  def open(): Unit = {}

  def process(key: KEY, window: W, input: Iterable[IN], out: Collector[OUT]): Unit

  def close(): Unit = {}

  override def apply(key: KEY, window: W, input: Iterable[IN], out: Collector[OUT]): Unit = {
    open()
    process(key, window, input, out)
    close()
  }
}
